from astoundlearning_app.models import StudySet, SetEntry
from google.appengine.ext import db

# This script is for manipulating the data on the live GAE datastore via the remote_api.
# If we need to manipulate the data on live GAE datastore, modify this script, and execute it:
# python manage.py shell --remote
# import job
# job.run_remote_job()
# quit()
def run_remote_job():
	all_decks = StudySet.all().fetch(1000)
	deck_count = 0
	entry_count = 0
	for deck in all_decks:
		deck_count = deck_count + 1
		entries_t = SetEntry.all().filter('set =', deck).fetch(100)
		while entries_t:
			entries = []
			for entry in entries_t:
				entry_count = entry_count + 1
				print entry.question
				entry.isPluginApplicable = True
				entry.isQuizOrTestApplicable = True
				entries.append(entry)
			entries_t = SetEntry.all().filter('set =', deck).filter('__key__ >', entries_t[-1].key()).fetch(100)
			print "Count of entries: " + str(len(entries))
			db.put(entries)
	print "Decks: " + str(deck_count) + ", Total entries: " + str(entry_count)
